<?php

class WishingwallAction extends IntesysAction
{
    public function _initialize()
    {
        parent::_initialize();
        $this->dao = D('Wishingwall');
        $_POST['site_id'] = __SITEID__;
    }

    public function index()
    {
        $this->display();
    }

    public function wall()
    {
        $this->list = $this->dao->where(array('site_id' => __SITEID__))->select();
        $this->display();
    }

    public function add()
    {
        echo $this->fetch();
    }


    public function insert()
    {
        $_POST['addtime'] = time();
        $_POST['member_id'] = $this->memberInfo['id'];
        $_POST['nickname'] = $this->memberInfo['nickname'];
        $_POST['name'] = $this->memberInfo['name'];
        $_POST['headimg'] = $this->memberInfo['img_url'];
        $_POST['color'] = $_POST['color_id'];

        if (!$this->dao->create()) {
            $this->error($this->dao->getError());
        }
        $id = $this->dao->add();
        $this->list = $this->dao->where(array('id' => $id))->select();
        echo $this->display('wall');
    }

    public function update_position()
    {
        if (!is_numeric($_GET['id']) || !is_numeric($_GET['x']) || !is_numeric($_GET['y']) || !is_numeric($_GET['z']))
            die("0");
        $id = intval($_GET['id']);
        $x = intval($_GET['x']);
        $y = intval($_GET['y']);
        $z = intval($_GET['z']);
        $data['xyz'] = $x . "|" . $y . "|" . $z;
        $this->dao->where(array('id' => $id))->save($data);
        echo '1';
    }
}